---@coding utf8

require("xlib.xoop.xclass")

---@class BaseClass:XClassType
local BaseClass = xclass("BaseClass")

function BaseClass:_constructor(id)
    ---@type integer
    self.id = id
end

function BaseClass:log_debug(msg)
    print(string.format("[id=%s] msg=%s", self.id, msg))
end

---@brief 用来测试继承，派生类不会实现这个函数
function BaseClass:Test()
    self:log_debug("BaseClass:Test")
end

---@brief 测试基类覆盖重写成员函数
function BaseClass:TestOverride()
    self:log_debug("BaseClass:TestOverride")
end

---@brief 派生类
---@class DerivedClass:BaseClass
local DerivedClass = xclass("DerivedClass", BaseClass)

function DerivedClass:_constructor(id)
    --TODO: 当前需要手工调用基类构造函数
    BaseClass._constructor(self, id)
    self.extend_id = id + 1
end

function DerivedClass:TestOverride()
    self:log_debug("DerivedClass:TestOverride")
end

---@type BaseClass
local obj = BaseClass(1)
obj:Test()
obj:TestOverride()
---@type DerivedClass
local derived_obj = DerivedClass(2)
derived_obj:Test()
derived_obj:TestOverride()